package com.sgb.kjwl.view.ui.activity.self.lease;

import android.annotation.SuppressLint;
import android.content.Context;
import android.content.Intent;
import android.graphics.Color;
import android.os.Bundle;
import android.text.Editable;
import android.text.InputType;
import android.text.TextUtils;
import android.text.TextWatcher;
import android.view.View;
import android.view.WindowManager;
import android.view.inputmethod.InputMethodManager;
import android.widget.EditText;
import android.widget.TextView;

import com.bigkoo.pickerview.builder.OptionsPickerBuilder;
import com.bigkoo.pickerview.builder.TimePickerBuilder;
import com.bigkoo.pickerview.view.OptionsPickerView;
import com.bigkoo.pickerview.view.TimePickerView;
import com.bumptech.glide.Glide;
import com.sdk.mobile.manager.login.NoDoubleClickListener;
import com.sgb.alimaplibrary.SelectAddressActivity;
import com.sgb.kjwl.AppActivity;
import com.sgb.kjwl.R;
import com.sgb.kjwl.databinding.ActivityLeaseOrderDeviceBinding;
import com.sgb.kjwl.di.machine.DaggerMachineComponent;
import com.sgb.kjwl.di.machine.MachineModule;
import com.sgb.kjwl.model.entity.lease.LeaseOrderEntity;
import com.sgb.kjwl.model.entity.lease.LeaseOrderInvoiceEntity;
import com.sgb.kjwl.model.entity.lease.OrderSnapshotEntity;
import com.sgb.kjwl.model.entity.lease.ProductPriceEntity;
import com.sgb.kjwl.model.entity.transport.MapLongAndLatEntity;
import com.sgb.kjwl.model.entity.user.AddressEntity;
import com.sgb.kjwl.utils.EditInputFilter;
import com.sgb.kjwl.viewmodel.machine.LeaseOrderDeviceModel;
import com.swgk.core.base.di.AppComponent;
import com.swgk.core.customview.CfkEditView;
import com.swgk.core.customview.ItemInputTextView;
import com.swgk.core.dialog.CommonDialog;
import com.swgk.core.util.DateUtils;
import com.swgk.core.util.MToast;
import com.swgk.core.util.PickSelectEntity;
import com.swgk.core.util.SharedPreferenceUtil;

import java.text.DecimalFormat;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;
import java.util.List;

import javax.inject.Inject;

import androidx.databinding.DataBindingUtil;

import org.json.JSONObject;

/**
 * 设备出租订单
 */
public class LeaseOrderDeviceActivity extends AppActivity implements ItemInputTextView.OnWholeItemClickListener {
    @Inject
    LeaseOrderDeviceModel viewModel;
    private ActivityLeaseOrderDeviceBinding binding;
    // 地址一级联动数据
    private List<AddressEntity<List<AddressEntity<List<AddressEntity>>>>> addressEntityList;
    // 地址二级联动数据
    private List<List<AddressEntity<List<AddressEntity>>>> opt2 = new ArrayList<>();
    // 地址三级联动数据
    private List<List<List<AddressEntity>>> opt3 = new ArrayList<>();
    private int cityPosition1;
    private int cityPosition2;
    private int cityPosition3;
    private Calendar selectedDate = Calendar.getInstance();
    private List<LeaseOrderInvoiceEntity> invoiceList;
    private List<PickSelectEntity> carrierData, driverData, contractTypes;
    private List<LeaseOrderEntity.ParamDtosBean> viewList = new ArrayList<>();
    private ProductPriceEntity productPriceEntity = new ProductPriceEntity();
    private int maxAge = 60;
    private String no;
    private String priceUnitNo;
    private String priceUnitName;//时长单位
    private String haveContract;//1代表合同租赁，0代表直接租赁
    private String leaseType = "3";//1, 无合同租赁 2, 合同租赁+未开通合同 3, 合同租赁+已开通合同
    private String vipDriverPrice;//会员价不含税
    private String vipDriverRatePrice;//会员价含税
    private int invoiceIndex = 0;//当前选择的发票数组下标
    private int driverIndex = 1;//当前选择的操作员数组下标
    private int carrierIndex = 0;//当前选择的运输数组下标
    private int contractTypesIndex = 0;//当前选择的租赁方式数组下标
    private String version;//1为老数据

    @Override
    protected void setupActivityComponent(AppComponent appComponent) {
        DaggerMachineComponent.builder().appComponent(appComponent)
                .machineModule(new MachineModule(this))
                .build()
                .inject(this);
    }

    public static void start(Context context, String id, String no, String num, String priceUnitNo, String priceUnitName, String haveContract, String leaseType, String vipDriverPrice, String vipDriverRatePrice) {
        Intent intent = new Intent(context, LeaseOrderDeviceActivity.class);
        intent.putExtra("id", id);
        intent.putExtra("no", no);
        intent.putExtra("num", num);
        intent.putExtra("priceUnitNo", priceUnitNo);
        intent.putExtra("priceUnitName", priceUnitName);
        intent.putExtra("haveContract", haveContract);
        intent.putExtra("leaseType", leaseType);
        intent.putExtra("vipDriverPrice", vipDriverPrice);
        intent.putExtra("vipDriverRatePrice", vipDriverRatePrice);
        context.startActivity(intent);
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE);
        //设置沉浸式状态栏的上移问题
        setTileImmerse(true);
    }

    @Override
    protected void initView() {
        binding = DataBindingUtil.setContentView(this, R.layout.activity_lease_order_device);
        binding.setViewModel(viewModel);
        binding.include.ivBack.setOnClickListener(v -> finish());
        binding.include.titleView.setText("填写订单");
        //binding.itvArea.setOnWholeItemClickListener(this);
        binding.timeCourse.setOnWholeItemClickListener(this);
        binding.itemTvInvoice.setOnWholeItemClickListener(this);
        binding.itemTvCarrier.setOnWholeItemClickListener(this);
        binding.itemTvDriver.setOnWholeItemClickListener(this);
//        binding.itemTvAge.setOnWholeItemClickListener(this);
//        binding.itemTvDriverAge.setOnWholeItemClickListener(this);
        binding.itemTvLeaseMode.setOnWholeItemClickListener(this);
        binding.tvAddInvoice.setOnClickListener(v -> LeaseInvoiceAddActivity.start(this));
        binding.tvAdd.setOnClickListener(v -> add());
        binding.tvSub.setOnClickListener(v -> sub());
        binding.tvAddView.setOnClickListener(v -> addView());
        binding.tvDelView.setOnClickListener(v -> delView());
        binding.tvInvoiceTip.setOnClickListener(v -> showInvoiceTip());
        binding.tvTransportTip.setOnClickListener(v -> showTransportTip());
        binding.tvTimeNum.setFilters(new EditInputFilter[]{new EditInputFilter(99, 1, 0)});
        binding.publicView.setOnClickListener(new NoDoubleClickListener() {
            @Override
            public void onNoDoubleClick(View view) {
                validateData();//提交订单按钮
            }
        });
        binding.itemTvInvoice.setContentTextEnd();
        binding.itemAddressDetail.setOnWholeItemClickListener(view -> {
            getAddress();
//                if (!TextUtils.isEmpty(binding.itvArea.getContent())) {
//                    //跳转详细地址界面
//                    viewModel.getLocationLL(
//                            viewModel.addEntity.get().getProvinceNo(),
//                            viewModel.addEntity.get().getCityNo(),
//                            viewModel.addEntity.get().getAreaNo());
//                } else {
//                    MToast.showToast(LeaseOrderDeviceActivity.this, "请选择使用地区");
//                }
        });

        binding.tvTimeNum.addTextChangedListener(new TextWatcher() {
            @Override
            public void beforeTextChanged(CharSequence s, int start, int count, int after) {

            }

            @Override
            public void onTextChanged(CharSequence s, int start, int before, int count) {
            }

            @Override
            public void afterTextChanged(Editable s) {
                if (!TextUtils.isEmpty(binding.tvTimeNum.getText())) {
                    setRentalTotalPrice();
                }
            }
        });

    }

    @Override
    protected void init() {
        initDefault();
        initData();
        viewModel.getAddressModel();//请求省市区数据
        no = getIntent().getStringExtra("no");
        String id = getIntent().getStringExtra("id");
        String num = getIntent().getStringExtra("num");
        viewModel.addEntity.get().setRentalNum(num);//租赁数量
        binding.itvTotalNum.setContent("x" + num);
        priceUnitNo = getIntent().getStringExtra("priceUnitNo");
        priceUnitName = getIntent().getStringExtra("priceUnitName");//时长单位从此获取
        haveContract = getIntent().getStringExtra("haveContract");
        leaseType = getIntent().getStringExtra("leaseType");
        vipDriverPrice = getIntent().getStringExtra("vipDriverPrice");
        vipDriverRatePrice = getIntent().getStringExtra("vipDriverRatePrice");
        if (!TextUtils.isEmpty(priceUnitName)) {//从h5获取时长单位
            binding.tvTimeUnit.setText(priceUnitName);
        }
        if ("1".equals(haveContract)) {
            binding.itemTvLeaseMode.setContent("合同租赁");
        } else {
            binding.itemTvLeaseMode.setContent("直接租赁");
        }
        if (!"3".equals(leaseType)) {//非 合同租赁+已开通合同 时不可选租赁方式
            binding.itemTvLeaseMode.setOnWholeItemClickListener(null);
            binding.itemTvLeaseMode.setArrowVisible(false);
        }
        viewModel.getSnapshot(id, "2");

    }

    //设置默认参数
    private void initDefault() {
        String myCompanyNo = SharedPreferenceUtil.getInstance().getSaveStringData(SharedPreferenceUtil.COMPANY_NO, "");
        viewModel.addEntity.get().setBuyerCompanyNo(myCompanyNo);
        String myCompanyName = SharedPreferenceUtil.getInstance().getSaveStringData(SharedPreferenceUtil.COMPANY_NAME, "");
        String contact = SharedPreferenceUtil.getInstance().getSaveStringData(SharedPreferenceUtil.REAL_NAME, "");
        String phone = SharedPreferenceUtil.getInstance().getSaveStringData(SharedPreferenceUtil.LOGIN_PHONE, "");
        binding.itemTvCompanyName.setContent(myCompanyName);
        binding.itemTvContact.setContent(contact);
        binding.itemTvPhone.setContent(phone);
        binding.itemTvPhone.setInputType(InputType.TYPE_CLASS_NUMBER);
        if (TextUtils.isEmpty(myCompanyNo) || "0".equals(myCompanyNo)) {//个人身份
            binding.itemTvCompanyName.setContent(contact);
//            binding.itemTvCompanyName.setVisibility(View.GONE);
//            binding.itemTvInvoice.setVisibility(View.GONE);
            binding.tvAddInvoice.setVisibility(View.VISIBLE);
            //如果是个人身份，则租赁方式不可选
            binding.itemTvLeaseMode.setOnWholeItemClickListener(null);
            binding.itemTvLeaseMode.setArrowVisible(false);
        }

    }

    //初始化发票选择数据
    private void initData() {
        //运输要求 1承租方 2 出租方
        carrierData = new ArrayList<>();
        carrierData.add(new PickSelectEntity("2", "出租方承担(运输费用协商解决)"));
        carrierData.add(new PickSelectEntity("1", "承租方承担"));
        binding.itemTvCarrier.setContent(carrierData.get(0).getProjectscale());
        viewModel.addEntity.get().setCarrier(carrierData.get(0).getNo());

        //操作员要求  1承租方 2 出租方"
        driverData = new ArrayList<>();
        driverData.add(new PickSelectEntity("2", "出租方提供"));
        driverData.add(new PickSelectEntity("1", "承租方提供"));
        binding.itemTvDriver.setContent(driverData.get(1).getProjectscale());
        viewModel.addEntity.get().setDriverProvider(driverData.get(1).getNo());

        //租赁方式  1代表合同租赁，0代表直接租赁
        contractTypes = new ArrayList<>();
        contractTypes.add(new PickSelectEntity("0", "直接租赁"));
        contractTypes.add(new PickSelectEntity("1", "合同租赁"));
    }

    private void addView() {
        if (binding.llDescGroup.getChildCount() >= 5) {
            MToast.showToast(this, "最多只能新增5条");
            return;
        }
        if (!getViewList()) {
            return;
        }
        View view = View.inflate(getActivity(), R.layout.layout_lease_order_item, null);
        binding.llDescGroup.addView(view, binding.llDescGroup.getChildCount());
        TextView tvDel = view.findViewById(R.id.tv_del);
        tvDel.setOnClickListener(view1 -> binding.llDescGroup.removeView(view));
        if (binding.llDescGroup.getChildCount() > 1) {
            View itemView = binding.llDescGroup.getChildAt(binding.llDescGroup.getChildCount() - 2);
            itemView.findViewById(R.id.tv_del).setVisibility(View.VISIBLE);
        }
        binding.tvDelView.setVisibility(View.VISIBLE);
    }

    private void delView() {
        if (binding.llDescGroup.getChildCount() > 0) {
            binding.llDescGroup.removeViewAt(binding.llDescGroup.getChildCount() - 1);
            if (binding.llDescGroup.getChildCount() == 0) {
                binding.tvDelView.setVisibility(View.GONE);
            } else {
                View itemView = binding.llDescGroup.getChildAt(binding.llDescGroup.getChildCount() - 1);
                itemView.findViewById(R.id.tv_del).setVisibility(View.GONE);
            }
        }

    }

    public boolean getViewList() {
        viewList.clear();
        for (int i = 0; i < binding.llDescGroup.getChildCount(); i++) {
            View view = binding.llDescGroup.getChildAt(i);
            String title = ((EditText) view.findViewById(R.id.tv_desc_title)).getText().toString().trim();
            String content = ((CfkEditView) view.findViewById(R.id.tv_desc_content)).getEditContent().trim();
            if (TextUtils.isEmpty(title) || TextUtils.isEmpty(content)) {
                MToast.showToast(this, "请完善新增要求");
                return false;
            }
            LeaseOrderEntity.ParamDtosBean bean = new LeaseOrderEntity.ParamDtosBean();
            bean.setNo(i);
            bean.setTitle(title);
            bean.setValue(content);
            viewList.add(bean);
        }
        return true;
    }

    //加
    private void add() {
        if (TextUtils.isEmpty(binding.tvTimeNum.getText())) {
            binding.tvTimeNum.setText("1");
        }
        int num = Integer.parseInt(binding.tvTimeNum.getText().toString());
        num += 1;
        if (num >= 99) {
            num = 99;
        }
        binding.tvTimeNum.setText(num + "");
        setRentalTotalPrice();
    }

    //减
    private void sub() {
        if (TextUtils.isEmpty(binding.tvTimeNum.getText())) {
            binding.tvTimeNum.setText("1");
        }
        int num = Integer.parseInt(binding.tvTimeNum.getText().toString());
        if (num <= 1) {
            num = 1;
        } else {
            num -= 1;
        }
        binding.tvTimeNum.setText(num + "");
        setRentalTotalPrice();
    }

    @Override
    public void OnWholeItemClick(View view) {
        switch (view.getId()) {
//            case R.id.itv_area://使用地区地址
//                if (addressEntityList != null) {
//                    showCityPop("请选择地区");
//                }
//                break;
//            case R.id.tv_address_select://详细地址
//                if (!TextUtils.isEmpty(binding.itvArea.getContent())) {
//                    //跳转详细地址界面
//                    viewModel.getLocationLL(
//                            viewModel.addEntity.get().getProvinceNo(),
//                            viewModel.addEntity.get().getCityNo(),
//                            viewModel.addEntity.get().getAreaNo());
//                } else {
//                    ToastUtils.show(this, "请选择所在地区");
//                }
//                break;
            case R.id.item_tv_invoice://选择发票
                if (binding.tvAddInvoice.getVisibility() == View.VISIBLE) {
                    viewModel.getPersonInvoicelist();//获取个人发票列表
                } else {
                    viewModel.getInvoiceList();//获取企业发票列表
                }
                break;
            case R.id.time_course://进场时间
                showTimeCoursePop();
                break;
            case R.id.item_tv_carrier://运输要求
                showCarrier();
                break;
            case R.id.item_tv_driver://驾驶员要求
                showDriver();
                break;
//            case R.id.item_tv_age://驾驶员年龄要求
//                showAge();
//                break;
//            case R.id.item_tv_driverAge://驾驶员驾龄要求
//                showDriverAge();
//                break;
            case R.id.item_tv_lease_mode://租赁方式
                showContractType();
                break;
            default:
                break;
        }
    }

    //租赁方式
    private void showContractType() {
        if (contractTypes != null && contractTypes.size() > 0) {
            OptionsPickerView businessOption = new OptionsPickerBuilder(this, (options1, options2, options3, v) -> {
                contractTypesIndex = options1;
                binding.itemTvLeaseMode.setContent(contractTypes.get(options1).getProjectscale());
                haveContract = contractTypes.get(options1).getNo();
                viewModel.addEntity.get().setHaveContract(contractTypes.get(options1).getNo());
            }).build();
            businessOption.setPicker(contractTypes);
            businessOption.setSelectOptions(contractTypesIndex);
            businessOption.show();
        }
    }

    //运输要求
    private void showCarrier() {
        if (carrierData != null && carrierData.size() > 0) {
            OptionsPickerView businessOption = new OptionsPickerBuilder(this, (options1, options2, options3, v) -> {
                carrierIndex = options1;
                binding.itemTvCarrier.setContent(carrierData.get(options1).getProjectscale());
                viewModel.addEntity.get().setCarrier(carrierData.get(options1).getNo());
            }).build();
            businessOption.setPicker(carrierData);
            businessOption.setSelectOptions(carrierIndex);
            businessOption.show();
        }
    }

    //驾驶员要求
    private void showDriver() {
        if (driverData != null && driverData.size() > 0) {
            OptionsPickerView businessOption = new OptionsPickerBuilder(this, (options1, options2, options3, v) -> {
                driverIndex = options1;
                binding.itemTvDriver.setContent(driverData.get(options1).getProjectscale());
                viewModel.addEntity.get().setDriverProvider(driverData.get(options1).getNo());
                if ("1".equals(driverData.get(options1).getNo())) {
                    binding.itemTvAge.setVisibility(View.GONE);
                    binding.itemTvDriverAge.setVisibility(View.GONE);
                } else {
                    binding.itemTvAge.setVisibility(View.VISIBLE);
                    binding.itemTvDriverAge.setVisibility(View.VISIBLE);
                }
                showPriceSelect();
            }).build();
            businessOption.setPicker(driverData);
            businessOption.setSelectOptions(driverIndex);
            businessOption.show();
        }
    }

    //开具发票对话框
//    private void showInvoice() {
//        if (invoiceList != null && invoiceList.size() > 0) {
//            OptionsPickerView businessOption = new OptionsPickerBuilder(this, (options1, options2, options3, v) -> {
//                LeaseOrderInvoiceEntity invoiceEntity = invoiceList.get(options1);
//                if (TextUtils.isEmpty(invoiceEntity.getNo())) {
//                    viewModel.addEntity.get().setBuyerNeedInvoice("0");//买家是否需要开具发票,0否，1是
//                    viewModel.addEntity.get().setInvoiceInfoDTO(null);
//                    binding.itemTvInvoice.setContent(invoiceEntity.getInvoiceTitle());
//                    binding.includeInvoice.llInvoice.setVisibility(View.GONE);
//                } else {
//                    viewModel.addEntity.get().setBuyerNeedInvoice("1");
//                    binding.itemTvInvoice.setContent(invoiceEntity.getInvoiceTitle());
//                    viewModel.addEntity.get().setInvoiceInfoDTO(invoiceEntity);
//                    binding.includeInvoice.llInvoice.setVisibility(View.VISIBLE);
//                    setInvoiceText(invoiceEntity);
//                }
//                showPriceSelect();
//            }).build();
//            businessOption.setPicker(invoiceList);
//            businessOption.setSelectOptions(0);
//            businessOption.show();
//        }
//    }


    private void setInvoiceText(LeaseOrderInvoiceEntity invoiceEntity) {
        binding.includeInvoice.setEntity(invoiceEntity);
        binding.includeInvoice.tvName.setText(invoiceEntity.getInvoiceTitle());
        binding.includeInvoice.tvAccountNo.setText(invoiceEntity.getCreditCode());
        binding.includeInvoice.tvBlankName.setText(invoiceEntity.getOwnerBank());
        binding.includeInvoice.tvBlankNo.setText(invoiceEntity.getBlankAccount());
        binding.includeInvoice.tvAdress.setText(invoiceEntity.getAddress());
        binding.includeInvoice.tvPhone.setText(invoiceEntity.getPhone());
    }


//    //发票选择对话框
//    private void showInvoiceDialog() {
//        if (invoiceDialog == null) {
//            invoiceDialog = LeaseOrderInvoiceDialog.newInstance(invoiceList, binding.itemTvInvoice.getContent());
//            invoiceDialog.setItemCallBack(new LeaseOrderInvoiceDialog.ItemCallBack() {
//                @Override
//                public void onSelect(LeaseOrderInvoiceEntity invoiceEntity) {
//                    if (invoiceEntity == null) {
//                        viewModel.addEntity.get().setBuyerNeedInvoice("0");//买家是否需要开具发票,0否，1是
//                        viewModel.addEntity.get().setInvoiceInfoDTO(null);
//                        binding.itemTvInvoice.setContent("否");
//                    } else {
//                        viewModel.addEntity.get().setBuyerNeedInvoice("1");
//                        binding.itemTvInvoice.setContent("是");
//                        viewModel.addEntity.get().setInvoiceInfoDTO(invoiceEntity);
//                    }
//                }
//            });
//        }
//        invoiceDialog.showAllowingLoss(getSupportFragmentManager(), "LeaseOrderInvoiceDialog");
//    }

    //进场时间选择器
    private void showTimeCoursePop() {
        Calendar dayCalendar = Calendar.getInstance();
        dayCalendar.setTime(new Date());
        dayCalendar.add(Calendar.DAY_OF_MONTH, 1);

        TimePickerView timePicker = new TimePickerBuilder(this, (date, v) -> {
            try {
                @SuppressLint("SimpleDateFormat") SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
                String format = sdf.format(date);

                viewModel.addEntity.get().setApproachTime(DateUtils.dateTo10Timestamp3(format + " 23:59:59"));//转为时间戳
                binding.timeCourse.setContent(format);
                selectedDate.setTime(date);
            } catch (Exception e) {
                e.printStackTrace();
            }
        }).setType(new boolean[]{true, true, true, false, false, false})
                .setCancelText("取消").setSubCalSize(15)
                .setCancelColor(Color.parseColor("#666666"))
                .setTitleText("请选择时间")
                .setTitleColor(Color.parseColor("#969696")).setTitleSize(15)
                .setSubmitText("确定")
                .setSubmitColor(Color.parseColor("#5792FD"))
                .setRangDate(dayCalendar, null)
                .build();
        timePicker.show();
        timePicker.setDate(selectedDate);
    }

//    //    选择地址弹窗
//    private void showCityPop(String title) {
//        CityPickView cityOption = new CityPickBuilder(this, new OnOptionsSelectListener() {
//            @Override
//            public void onOptionsSelect(int options1, int options2, int options3, View v) {
//                String areaName = "";
//                if (opt3.get(options1).get(options2).get(options3) == null) {
//                    areaName = "";
//                } else {
//                    areaName = opt3.get(options1).get(options2).get(options3).getName();
//                    cityPosition3 = options3;
//                    viewModel.addEntity.get().setAreaNo(opt3.get(options1).get(options2).get(options3).getNo());
//                }
//                String content = addressEntityList.get(options1).getName() + " / " + opt2.get(options1).get(options2).getName() + " / " + areaName;
//                cityPosition1 = options1;
//                cityPosition2 = options2;
//                //设置显示
//                binding.itvArea.setContent(content);
//                binding.addressDetail.setText("");
//                binding.addressDetail.setVisibility(View.GONE);
//                viewModel.addEntity.get().setProvinceNo(addressEntityList.get(options1).getNo());
//                viewModel.addEntity.get().setCityNo(opt2.get(options1).get(options2).getNo());
//            }
//        }).setCancelText("取消").setSubCalSize(15)
//                .setCancelColor(Color.parseColor("#666666"))
//                .setTitleText(title)
//                .setTitleColor(Color.parseColor("#969696")).setTitleSize(15)
//                .setSubmitText("确定")
//                .setSubmitColor(Color.parseColor("#5792FD"))
//                .build();
//        cityOption.setPicker(addressEntityList, opt2, opt3);
//        cityOption.setSelectOptions(cityPosition1, cityPosition2, cityPosition3);
//        cityOption.show();
//    }
//
//    private void showAge() {
//        TwoRangePopWindow twoRangePopWindow = new TwoRangePopWindow(getActivity());
//        twoRangePopWindow.setOnCallBack(new TwoRangePopWindow.OnCallBack() {
//
//            @Override
//            public void result(int startTime, int endTime, String content) {
//                if (startTime < endTime) {
//                    maxAge = endTime;
//                    viewModel.addEntity.get().setMinDriverAge(String.valueOf(startTime));
//                    viewModel.addEntity.get().setMaxDriverAge(String.valueOf(endTime));
//                    binding.itemTvAge.setContent(content);
//                    binding.itemTvDriverAge.setContent("");//清空驾龄范围,重新选择
//                    twoRangePopWindow.dismiss();
//                } else {
//                    MToast.showToast(LeaseOrderDeviceActivity.this, "最大年龄必须大于等于最小年龄");
//                }
//
//            }
//        });
//        twoRangePopWindow.setData(getAgeData(18, 59), getAgeData(19, 60));
//        twoRangePopWindow.setCurrentItem(0, 21);
//        twoRangePopWindow.setBgView(binding.grayLayout);
//        twoRangePopWindow.showPopwindowBottom(binding.publicView);
//        twoRangePopWindow.setTitle("驾驶员年龄");
//    }
//
//    private List<TwoRangePopWindow.SourceEntity> getAgeData(int start, int end) {
//        List<TwoRangePopWindow.SourceEntity> mOptionsItems = new ArrayList<>();
//        for (int i = start; i <= end; i++) {
//            mOptionsItems.add(new TwoRangePopWindow.SourceEntity(i + "", i));
//        }
//        return mOptionsItems;
//    }
//
//    private void showDriverAge() {
//        TwoRangePopWindow twoRangePopWindow = new TwoRangePopWindow(getActivity());
//        twoRangePopWindow.setOnCallBack(new TwoRangePopWindow.OnCallBack() {
//
//            @Override
//            public void result(int startTime, int endTime, String content) {
//                if (startTime < endTime) {
//                    viewModel.addEntity.get().setMinDrivingAge(String.valueOf(startTime));
//                    viewModel.addEntity.get().setMaxDrivingAge(String.valueOf(endTime));
//                    binding.itemTvDriverAge.setContent(content);
//                    twoRangePopWindow.dismiss();
//                } else {
//                    MToast.showToast(LeaseOrderDeviceActivity.this, "最大驾龄必须大于等于最小驾龄");
//                }
//
//            }
//        });
//        twoRangePopWindow.setData(getAgeData(0, maxAge - 19), getAgeData(1, maxAge - 18));
//        twoRangePopWindow.setCurrentItem(0, 2);
//        twoRangePopWindow.setBgView(binding.grayLayout);
//        twoRangePopWindow.showPopwindowBottom(binding.publicView);
//        twoRangePopWindow.setTitle("驾驶员驾龄");
//    }

    //返回省市区数据加载数据
    public void initAddressData(List<AddressEntity<List<AddressEntity<List<AddressEntity>>>>> data) {
        addressEntityList = data;
        initJsonData();
    }

    //组装省市区数据信息
    private void initJsonData() {
        for (int i = 0; i < addressEntityList.size(); i++) {
            ArrayList areaList = new ArrayList<>();
            opt2.add(addressEntityList.get(i).getChildren());
            for (int j = 0; j < addressEntityList.get(i).getChildren().size(); j++) {
                List<AddressEntity> cityAreaList = new ArrayList<>();
                List<AddressEntity> children = addressEntityList.get(i).getChildren().get(j).getChildren();
                if (children == null || children.size() == 0) {
                    cityAreaList.add(null);
                } else {
                    cityAreaList.addAll(children);
                }
                areaList.add(cityAreaList);
            }
            opt3.add(areaList);
        }
    }

    //开具发票对话框
    public void setLeaseOrderInvoiceList(List<LeaseOrderInvoiceEntity> list) {
        if (list == null) {
            list = new ArrayList<>();
        }
        //添加默认发票
        LeaseOrderInvoiceEntity entity = new LeaseOrderInvoiceEntity();
        entity.setInvoiceTitle("不开发票");
        list.add(0, entity);

        invoiceList = list;
        if (TextUtils.isEmpty(binding.itemTvInvoice.getContent().trim())) {
            binding.itemTvInvoice.setContent("不开发票");
            viewModel.addEntity.get().setBuyerNeedInvoice("0");//买家是否需要开具发票,0否，1是
            viewModel.addEntity.get().setInvoiceInfoDTO(null);
        }
        if (invoiceList != null && invoiceList.size() > 0) {
            OptionsPickerView businessOption = new OptionsPickerBuilder(this, (options1, options2, options3, v) -> {
                invoiceIndex = options1;
                LeaseOrderInvoiceEntity invoiceEntity = invoiceList.get(options1);
                if (TextUtils.isEmpty(invoiceEntity.getNo())) {
                    viewModel.addEntity.get().setBuyerNeedInvoice("0");//买家是否需要开具发票,0否，1是
                    viewModel.addEntity.get().setInvoiceInfoDTO(null);
                    binding.itemTvInvoice.setContent(invoiceEntity.getInvoiceTitle());
                    binding.includeInvoice.llInvoice.setVisibility(View.GONE);
                } else {
                    viewModel.addEntity.get().setBuyerNeedInvoice("1");
                    binding.itemTvInvoice.setContent(invoiceEntity.getInvoiceTitle());
                    viewModel.addEntity.get().setInvoiceInfoDTO(invoiceEntity);
                    binding.includeInvoice.llInvoice.setVisibility(View.VISIBLE);
                    setInvoiceText(invoiceEntity);
                }
                showPriceSelect();
            }).build();
            businessOption.setPicker(invoiceList);
            businessOption.setSelectOptions(invoiceIndex);
            businessOption.show();
        }
    }

    public void showProductPriceEntity(ProductPriceEntity entity) {
        this.productPriceEntity = entity;
//        if (!TextUtils.isEmpty(entity.getTimeName())) {//从接口获取时长单位
//            binding.tvTimeUnit.setText(entity.getTimeName());
//        }
        showPriceSelect();
    }

    //快照价格显示
    @SuppressLint("SetTextI18n")
    private void showPriceSelect() {
        if (productPriceEntity != null) {//非面议情况下的价格设置
            binding.priceViewUnit.setText(productPriceEntity.getPriceUnitName());
            if ("1".equals(viewModel.addEntity.get().getBuyerNeedInvoice())) {//用户选择开具发票
                if ("2".equals(viewModel.addEntity.get().getDriverProvider())) {//用户选择出租方提供操作员
                    if (!TextUtils.isEmpty(productPriceEntity.getDriverReatePrice())) {//有设置开发票的价格,有设置了带操作员价格
                        binding.priceView.setText(productPriceEntity.getDriverReatePrice());
                        binding.priceViewLabel.setText("(含操作员、含税)");
                        viewModel.addEntity.get().setHaveRate("1");//含税
                        viewModel.addEntity.get().setHaveDriver("1");//含操作员
                    } else if (!TextUtils.isEmpty(productPriceEntity.getNoDriverReatePrice())) {//有设置开发票的价格,只设置了不带操作员价格
                        binding.priceView.setText(productPriceEntity.getNoDriverReatePrice());
                        binding.priceViewLabel.setText("(不含操作员、含税)");
                        viewModel.addEntity.get().setHaveRate("1");
                        viewModel.addEntity.get().setHaveDriver("0");
                    } else if (!TextUtils.isEmpty(productPriceEntity.getDriverPrice())) {//未设置不开发票的价格,只设置了带操作员价格(匹配不上的处理)
                        binding.priceView.setText(productPriceEntity.getDriverPrice());
                        binding.priceViewLabel.setText("(含操作员、不含税)");
                        viewModel.addEntity.get().setHaveRate("0");
                        viewModel.addEntity.get().setHaveDriver("1");
                    } else if (!TextUtils.isEmpty(productPriceEntity.getNoDriverPrice())) {//未设置不开发票的价格,只设置了不带操作员价格(匹配不上的处理)
                        binding.priceView.setText(productPriceEntity.getNoDriverPrice());
                        binding.priceViewLabel.setText("(不含操作员、不含税)");
                        viewModel.addEntity.get().setHaveRate("0");
                        viewModel.addEntity.get().setHaveDriver("0");
                    }
                } else {//用户选择承租方提供操作员
                    if (!TextUtils.isEmpty(productPriceEntity.getNoDriverReatePrice())) {
                        binding.priceView.setText(productPriceEntity.getNoDriverReatePrice());
                        binding.priceViewLabel.setText("(不含操作员、含税)");
                        viewModel.addEntity.get().setHaveRate("1");
                        viewModel.addEntity.get().setHaveDriver("0");
                    } else if (!TextUtils.isEmpty(productPriceEntity.getDriverReatePrice())) {
                        binding.priceView.setText(productPriceEntity.getDriverReatePrice());
                        binding.priceViewLabel.setText("(含操作员、含税)");
                        viewModel.addEntity.get().setHaveRate("1");
                        viewModel.addEntity.get().setHaveDriver("1");
                    } else if (!TextUtils.isEmpty(productPriceEntity.getNoDriverPrice())) {
                        binding.priceView.setText(productPriceEntity.getNoDriverPrice());
                        binding.priceViewLabel.setText("(不含操作员、不含税)");
                        viewModel.addEntity.get().setHaveRate("0");
                        viewModel.addEntity.get().setHaveDriver("0");
                    } else if (!TextUtils.isEmpty(productPriceEntity.getDriverPrice())) {
                        binding.priceView.setText(productPriceEntity.getDriverPrice());
                        binding.priceViewLabel.setText("(含操作员、不含税)");
                        viewModel.addEntity.get().setHaveRate("0");
                        viewModel.addEntity.get().setHaveDriver("1");
                    }
                }
            } else {//用户选择不开发票
                if ("2".equals(viewModel.addEntity.get().getDriverProvider())) {//用户选择出租方提供操作员
                    if (!TextUtils.isEmpty(productPriceEntity.getDriverPrice())) {
                        binding.priceView.setText(productPriceEntity.getDriverPrice());
                        binding.priceViewLabel.setText("(含操作员、不含税)");
                        viewModel.addEntity.get().setHaveRate("0");
                        viewModel.addEntity.get().setHaveDriver("1");
                    } else if (!TextUtils.isEmpty(productPriceEntity.getNoDriverPrice())) {
                        binding.priceView.setText(productPriceEntity.getNoDriverPrice());
                        binding.priceViewLabel.setText("(不含操作员、不含税)");
                        viewModel.addEntity.get().setHaveRate("0");
                        viewModel.addEntity.get().setHaveDriver("0");
                    }
                } else {//用户选择承租方提供操作员
                    if (!TextUtils.isEmpty(productPriceEntity.getNoDriverPrice())) {
                        binding.priceView.setText(productPriceEntity.getNoDriverPrice());
                        binding.priceViewLabel.setText("(不含操作员、不含税)");
                        viewModel.addEntity.get().setHaveRate("0");
                        viewModel.addEntity.get().setHaveDriver("0");
                    } else if (!TextUtils.isEmpty(productPriceEntity.getDriverPrice())) {
                        binding.priceView.setText(productPriceEntity.getDriverPrice());
                        binding.priceViewLabel.setText("(含操作员、不含税)");
                        viewModel.addEntity.get().setHaveRate("0");
                        viewModel.addEntity.get().setHaveDriver("1");
                    }
                }

            }

            //判断会员价是否含税
            if ("1".equals(viewModel.addEntity.get().getBuyerNeedInvoice())) {//用户选择开具发票
                if (!TextUtils.isEmpty(vipDriverRatePrice)) {//有会员价含税
                    binding.priceView.setText(vipDriverRatePrice);
                    binding.priceViewLabel.setText("(含操作员、含税)");
                    viewModel.addEntity.get().setHaveRate("1");
                    viewModel.addEntity.get().setHaveDriver("1");
                } else if (!TextUtils.isEmpty(vipDriverPrice)) {//没有设置含税会员价时
                    binding.priceView.setText(vipDriverPrice);
                    binding.priceViewLabel.setText("(含操作员、不含税)");
                    viewModel.addEntity.get().setHaveRate("0");
                    viewModel.addEntity.get().setHaveDriver("1");
                }
            } else {
                if (!TextUtils.isEmpty(vipDriverPrice)) {//有会员价不含税
                    binding.priceView.setText(vipDriverPrice);
                    binding.priceViewLabel.setText("(含操作员、不含税)");
                    viewModel.addEntity.get().setHaveRate("0");
                    viewModel.addEntity.get().setHaveDriver("1");
                }
            }

            if ("1".equals(version)) {//兼容老数据
                if (!TextUtils.isEmpty(productPriceEntity.getNoDriverPrice())) {
                    binding.priceView.setText(productPriceEntity.getNoDriverPrice());
                    binding.priceViewLabel.setText("(不含操作员、不含税)");
                    viewModel.addEntity.get().setHaveRate("0");
                    viewModel.addEntity.get().setHaveDriver("0");
                } else if (!TextUtils.isEmpty(productPriceEntity.getDriverPrice())) {
                    binding.priceView.setText(productPriceEntity.getDriverPrice());
                    binding.priceViewLabel.setText("(含操作员、不含税)");
                    viewModel.addEntity.get().setHaveRate("0");
                    viewModel.addEntity.get().setHaveDriver("1");
                } else if (!TextUtils.isEmpty(productPriceEntity.getNoDriverReatePrice())) {
                    binding.priceView.setText(productPriceEntity.getNoDriverReatePrice());
                    binding.priceViewLabel.setText("(不含操作员、含税)");
                    viewModel.addEntity.get().setHaveRate("1");
                    viewModel.addEntity.get().setHaveDriver("0");
                } else if (!TextUtils.isEmpty(productPriceEntity.getDriverReatePrice())) {
                    binding.priceView.setText(productPriceEntity.getDriverReatePrice());
                    binding.priceViewLabel.setText("(含操作员、含税)");
                    viewModel.addEntity.get().setHaveRate("1");
                    viewModel.addEntity.get().setHaveDriver("1");
                }
            }

        }

        setRentalTotalPrice();
    }

    public void showOrderMachineDeatilEntity(OrderSnapshotEntity entity) {
        viewModel.addEntity.get().setOrderSnapshotDTO(entity);
        if (entity != null) {
            try {
                JSONObject jsonObject = new JSONObject(entity.getProductInfo());
                version = jsonObject.getString("version");
            }catch (Exception ex){
            }
            binding.titleView.setText(entity.getTitle());
            binding.tvArea.setText(entity.getAddress());
            binding.tvIsSelf.setVisibility("1".equals(entity.getIsSelf()) ? View.VISIBLE : View.GONE);
            if (!TextUtils.isEmpty(entity.getProductCompanyName())) {
                binding.tvLeaseName.setText(entity.getProductCompanyName());
            } else {
                binding.tvLeaseName.setText(entity.getContactName());
                //如果是个人身份，则租赁方式不可选
                binding.itemTvLeaseMode.setOnWholeItemClickListener(null);
                binding.itemTvLeaseMode.setArrowVisible(false);
            }
            Glide.with(this).load(entity.getPicture()).into(binding.logoView);
            //设置发票显示
//            if ("1".equals(entity.getNeedInvoice())) {
//                if ("1".equals(entity.getInvoiceType())) {
//                    binding.itvInvoiceText.setContent("专用发票," + entity.getTariff() + "%");
//                    viewModel.addEntity.get().setSellerInvoiceType("1");
//                } else {
//                    binding.itvInvoiceText.setContent("普通发票," + entity.getTariff() + "%");
//                    viewModel.addEntity.get().setSellerInvoiceType("0");
//                }
//                viewModel.addEntity.get().setSellerTariff(entity.getTariff());
//                viewModel.addEntity.get().setSellerProvideInvoice("1");
//                binding.itvInvoiceText.setVisibility(View.VISIBLE);
//            } else {
//                binding.itvInvoiceText.setVisibility(View.GONE);
//                viewModel.addEntity.get().setSellerProvideInvoice("0");
//            }

            //买家是否需要开具发票,0否，1是,默认否
            viewModel.addEntity.get().setBuyerNeedInvoice("0");
            binding.itemTvInvoice.setContent("不开发票");
            if ("1".equals(entity.getNegotiable())) {
                binding.priceView.setText("面议");
                binding.priceViewLabel.setVisibility(View.GONE);
                binding.priceViewUnit.setVisibility(View.GONE);
                viewModel.addEntity.get().setRentalPrice("0");
                viewModel.addEntity.get().setRentalTotalPrice("0");//总租金
            } else {
                binding.priceViewLabel.setVisibility(View.VISIBLE);
                binding.priceViewUnit.setVisibility(View.VISIBLE);
                binding.priceView.setText(entity.getProductPrice());
            }
        }

        if (!TextUtils.isEmpty(priceUnitNo)) {
            viewModel.getPriceImg(no, "2", priceUnitNo);
        }
    }

    /**
     * 设置总租金和合计显示
     */
    private void setRentalTotalPrice() {
        try {
            if (TextUtils.isEmpty(binding.tvTimeNum.getText())) {
                binding.tvTimeNum.setText("1");
            }
            String countStr = binding.itvTotalNum.getContent().replace("x", "");
            int count = TextUtils.isEmpty(countStr) ? 1 : Integer.parseInt(countStr);//租赁数量
            int timeNum = Integer.parseInt(binding.tvTimeNum.getText().toString()); //租赁时长
            double price = Double.parseDouble(binding.priceView.getText().toString().trim());
            double total = price * timeNum * count;
            binding.itvTotalPrice.setContent("￥" + toFormat(total));
            binding.tvOrderTotal.setText("￥" + toFormat(total));
            viewModel.addEntity.get().setRentalPrice(toFormat(price));
            viewModel.addEntity.get().setRentalTotalPrice(toFormat(total));//总租金
        } catch (Exception exception) {
            viewModel.addEntity.get().setRentalPrice("0");
            viewModel.addEntity.get().setRentalTotalPrice("0");//总租金
        }
    }

    //发布数据
    private void validateData() {
        if (TextUtils.isEmpty(binding.itemTvContact.getContent())) {
            MToast.showToast(this, "请完善联系人");
            return;
        } else if (TextUtils.isEmpty(binding.itemTvPhone.getContent())) {
            MToast.showToast(this, "请完善联系电话");
            return;
//        } else if (TextUtils.isEmpty(binding.itvArea.getContent())) {
//            MToast.showToast(this, "请完善使用地区");
//            return;
        } else if (TextUtils.isEmpty(binding.addressDetail.getText().toString())) {
            MToast.showToast(this, "请完善工作地址");
            return;
        } else if (TextUtils.isEmpty(binding.timeCourse.getContent())) {
            MToast.showToast(this, "请完善进场时间");
            return;
        } else if (TextUtils.isEmpty(binding.tvTimeNum.getText())) {
            MToast.showToast(this, "请填写租赁时长");
            return;
//        } else if (TextUtils.isEmpty(binding.leasePaint.getEditContent())) {
//            MToast.showToast(this, "请完善燃料要求");
//            return;
//        } else if (TextUtils.isEmpty(binding.leaseRepair.getEditContent())) {
//            MToast.showToast(this, "请完善维修要求");
//            return;
//        } else if (binding.itemTvAge.getVisibility() == View.VISIBLE && TextUtils.isEmpty(binding.itemTvAge.getContent())) {
//            MToast.showToast(this, "请选择驾驶员年龄范围");
//            return;
//        } else if (binding.itemTvDriverAge.getVisibility() == View.VISIBLE && TextUtils.isEmpty(binding.itemTvDriverAge.getContent())) {
//            MToast.showToast(this, "请选择驾驶员驾龄范围");
//            return;
        }
        if (getViewList()) {
            viewModel.addEntity.get().setCostExplainOther(viewList);
        } else {
            return;
        }

        viewModel.addEntity.get().setBuyerCompanyName(binding.itemTvCompanyName.getContent());
        viewModel.addEntity.get().setContactName(binding.itemTvContact.getContent());
        viewModel.addEntity.get().setContactPhone(binding.itemTvPhone.getContent());
        viewModel.addEntity.get().setRentalTime(binding.tvTimeNum.getText().toString());//租赁时长
        viewModel.addEntity.get().setFuelCostExplain(binding.leasePaint.getEditContent());//燃料费用说明
        viewModel.addEntity.get().setRepairCostExplain(binding.leaseRepair.getEditContent());//维修费用说明
        viewModel.addEntity.get().setInstallRequirement(binding.cevInstallation.getEditContent());//安装要求
        viewModel.addEntity.get().setPaymentWay("1");//默认1为全额付款
        viewModel.addEntity.get().setRentalPriceUnitNo(productPriceEntity.getPriceUnitNo());
        viewModel.addEntity.get().setRentalPriceUnitName(productPriceEntity.getPriceUnitName());
        viewModel.addEntity.get().setHaveContract(haveContract);
        viewModel.leaseOrder();
    }

    public void showSuccess(String id) {
        LeaseOrderSuccessActivity.start(this, id, "2");
    }

    //  返回经纬度信息
    public void getLocationLL(MapLongAndLatEntity data) {
        if (!TextUtils.isEmpty(data.getLat())) {
            if (!TextUtils.isEmpty(data.getLng())) {
                Intent intent = new Intent();
                intent.setClass(this, SelectAddressActivity.class);
                intent.putExtra(SelectAddressActivity.TITLE, "详细地址");
                intent.putExtra(SelectAddressActivity.HINT, "请输入地址");
                intent.putExtra(SelectAddressActivity.SAVE_TEXT, "确定");
                intent.putExtra(SelectAddressActivity.LATITUDE, Double.parseDouble(data.getLat()));
                intent.putExtra(SelectAddressActivity.LONGTITUDE, Double.parseDouble(data.getLng()));
                startActivityForResult(intent, 255);
            }
        }
    }

    //  跳转地图
    public void getAddress() {
        Intent intent = new Intent();
        intent.setClass(this, SelectAddressActivity.class);
        intent.putExtra(SelectAddressActivity.TITLE, "详细地址");
        intent.putExtra(SelectAddressActivity.HINT, "请输入地址");
        intent.putExtra(SelectAddressActivity.SAVE_TEXT, "确定");
//        if(!TextUtils.isEmpty(SharedPreferenceUtil.getInstance().getSaveStringData("LONGITUDE_ID",""))){
//            intent.putExtra(SelectAddressActivity.LATITUDE, Double.parseDouble(SharedPreferenceUtil.getInstance().getSaveStringData("LATITUDE_ID","")));
//            intent.putExtra(SelectAddressActivity.LONGTITUDE, Double.parseDouble(SharedPreferenceUtil.getInstance().getSaveStringData("LONGITUDE_ID","")));
//        }
        startActivityForResult(intent, 255);
    }

    @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        super.onActivityResult(requestCode, resultCode, data);
        if (resultCode == RESULT_OK) {
            if (requestCode == 255) {
                if (data == null) {
                    return;
                }
                double lat = data.getDoubleExtra(SelectAddressActivity.LATITUDE, 0);
                double lon = data.getDoubleExtra(SelectAddressActivity.LONGTITUDE, 0);
                String address = data.getStringExtra(SelectAddressActivity.CURRENT_POSITION);
                binding.addressDetail.setText(address + "");
                binding.addressDetail.setVisibility(View.VISIBLE);
                binding.itemAddressDetail.setHint("");
                viewModel.addEntity.get().setLatitude(lat + "");
                viewModel.addEntity.get().setLongitude(lon + "");
                viewModel.addEntity.get().setAddress(address + "");
            }
        }
    }

    public static void hideKeyboard(View view) {
        InputMethodManager imm = (InputMethodManager) view.getContext()
                .getSystemService(Context.INPUT_METHOD_SERVICE);
        if (imm != null) {
            imm.hideSoftInputFromWindow(view.getWindowToken(), 0);
        }
    }

    private String toFormat(double d) {
        return new DecimalFormat("#0.00").format(d);
    }

    private void showInvoiceTip() {
        new CommonDialog(getActivity()).builder().setPositiveButton("知道了")
                .setTitle("提示")
                .setMsg("如果没有开票信息，请联系管理员添加")
                .setDialogCallBack(new CommonDialog.DialogCallBack() {
                    @Override
                    public void onRightClick() {

                    }

                    @Override
                    public void onLeftClick() {

                    }
                }).show();
    }

    private void showTransportTip() {
        new CommonDialog(getActivity()).builder().setPositiveButton("知道了")
                .setTitle("提示")
                .setMsg("出租方运输时，出租方在接单时会修改协商后的运费；承租方运输时，运费固定为0元。")
                .setDialogCallBack(new CommonDialog.DialogCallBack() {
                    @Override
                    public void onRightClick() {

                    }

                    @Override
                    public void onLeftClick() {

                    }
                }).show();
    }

}
